<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html lang="UTF-8">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/font-awesome.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/main.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/carousel.css">
    <style>
        .tree li {
            list-style-type: none;
            cursor: pointer;
        }

        table tbody tr:nth-child(odd) {
            background: #F4F4F4;
        }

        table tbody td:nth-child(even) {
            color: #C00;
        }
        th, td {
            vertical-align: middle;
            text-align: center;
        }
    </style>
</head>

<body>
<div class="navbar-wrapper ">
    <%--动态导入另一个jsp页面，作用：将公共使用的部分提取出来，然后使用动态导入
              动态导入是不会导入include页面的编译指令的，而是仅仅将被导入页面的body内容插入本页面。--%>
    <jsp:include page="admin-header.jsp"></jsp:include>
</div>
<div class="container-fluid">
    <div class="row">
        <%--动态导入另一个jsp页面，作用：将公共使用的部分提取出来，然后使用动态导入
                     动态导入是不会导入include页面的编译指令的，而是仅仅将被导入页面的body内容插入本页面。--%>
        <jsp:include page="admin-left.jsp"></jsp:include>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 报修单清单</h3>
                </div>
                <div class="panel-body">
                    <br>
                    <hr style="clear:both;">
                    <div class="col-md-12 table-responsive">
                        <table class="table table-hover">
                            <thead>
                            <tr>
                                <th width="30">#</th>
                                <th>标题</th>
                                <th>缓急程度</th>
                                <th>维修负责人</th>
                                <th>状态</th>
                                <th>申请日期</th>
                                <th>是否有效</th>
                                <th>操作</th>
                                <th>指派报修单</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach var="tbOrderPageInfo" items="${tbOrderPageInfos.list}">
                                <tr>
                                    <td><span data-toggle="tooltip" title="#">${tbOrderPageInfo.orderId}</span></td>
                                    <td><a href="javascript:void(0);"
                                           onclick="lookDetail(${tbOrderPageInfo.orderId},1)">
                                            <span data-toggle="tooltip"
                                                  title="标题">${tbOrderPageInfo.machineModel}</span></a></td>
                                    <td><span data-toggle="tooltip"
                                              title="缓急程度">${tbOrderPageInfo.problemLever}</span></td>
                                    <td><span data-toggle="tooltip"
                                              title="维修负责人">${tbOrderPageInfo.tbLeader.leaderName}</span></td>
                                    <td>${tbOrderPageInfo.statu}</td>
                                    <td><fmt:formatDate value="${tbOrderPageInfo.addTime}"
                                                        pattern="yyyy-MM-dd"/></td>
                                    <c:if test="${tbOrderPageInfo.isDeleted == true}">
                                        <td><a type="button" class="btn btn-danger btn-xs"><span
                                            data-toggle="tooltip" title="无效">无效</span></a></td>
                                    </c:if>
                                    <c:if test="${tbOrderPageInfo.isDeleted == false}">
                                        <td><a type="button" class="btn btn-success btn-xs"><span
                                            data-toggle="tooltip" title="有效">有效</span></a></td>
                                    </c:if>
                                    <td>
                                        <a href="javascript:void(0);"
                                           onclick="setStatu(${tbOrderPageInfo.orderId},2)"
                                           class="btn btn-success btn-xs">
                                            <i class=" glyphicon glyphicon-check"></i><span data-toggle="tooltip"
                                                                                            title="待处理 处理中 驳回">设置状态</span>
                                        </a>
                                        <button type="button"
                                                onclick="DongJieOrder(${tbOrderPageInfo.orderId},${tbOrderPageInfo.isDeleted})"
                                                class="btn btn-warning btn-xs"><i
                                            class="glyphicon glyphicon-adjust"></i>
                                            <span data-toggle="tooltip" title="提示，如果无效，再次点击测激活，反之亦然">冻结</span>
                                        </button>
                                        <button type="button"
                                                onclick="DeleteOrder(${tbOrderPageInfo.orderId})"
                                                class="btn btn-danger btn-xs"><i
                                            class="glyphicon glyphicon-remove"></i>
                                            <span data-toggle="tooltip" title="删除报修单">删除</span>
                                        </button>
                                    </td>
                                    <c:if test="${tbOrderPageInfo.isDeleted == false}">
                                        <td>
                                            <button type="button" onclick="zdleader(${tbOrderPageInfo.orderId})"
                                                    class="btn btn-success btn-xs"><i
                                                class="glyphicon glyphicon-check"></i>
                                                <span data-toggle="tooltip" title="指定维修负责人">指派</span>
                                            </button>
                                        </td>
                                    </c:if>
                                    <c:if test="${tbOrderPageInfo.isDeleted == true}">
                                        <td>
                                            <button type="button" disabled
                                                    onclick="zdleader(${tbOrderPageInfo.orderId},${tbOrderPageInfo.isDeleted})"
                                                    class="btn btn-success btn-xs"><i
                                                class="glyphicon glyphicon-remove"></i>
                                                <span data-toggle="tooltip" title="此报修单无效">指派</span>
                                            </button>
                                        </td>
                                    </c:if>
                                </tr>
                            </c:forEach>
                            </tbody>
                            <tfoot>
                            <tr>
                                <td colspan="9" align="center">
                                    当前${tbOrderPageInfos.pageNum }页,总${tbOrderPageInfos.pages }页,总${tbOrderPageInfos.total }条记录
                                </td>
                            </tr>
                            <tr>
                                <td colspan="9" align="center">
                                    <ul class="pagination">
                                        <li><a
                                            href="${pageContext.request.contextPath}/tbOrder/searchOrders?page=1">首页</a>
                                        </li>
                                        <!-- 判断是否有上一页，以便显示点击按钮 -->
                                        <c:if test="${tbOrderPageInfos.hasPreviousPage }">
                                            <li>
                                                <a href="${pageContext.request.contextPath}/tbOrder/searchOrders?page=${tbOrderPageInfos.pageNum-1 }"
                                                   aria-label="Previous">
                                                    <span aria-hidden="true">&laquo;</span>
                                                </a>
                                            </li>
                                        </c:if>
                                        <!-- 遍历页码 -->
                                        <c:forEach items="${tbOrderPageInfos.navigatepageNums }" var="page_Num">
                                            <c:if test="${page_Num == tbOrderPageInfos.pageNum }">
                                                <li class="active"><a href="#">${page_Num }</a></li>
                                            </c:if>
                                            <c:if test="${page_Num != tbOrderPageInfos.pageNum }">
                                                <li><a
                                                    href="${pageContext.request.contextPath}/tbOrder/searchOrders?page=${page_Num }">${page_Num }</a>
                                                </li>
                                            </c:if>
                                        </c:forEach>
                                        <!-- 判断是否有下一页 -->
                                        <c:if test="${tbOrderPageInfos.hasNextPage }">
                                            <li>
                                                <a href="${pageContext.request.contextPath}/tbOrder/searchOrders?page=${tbOrderPageInfos.pageNum+1 }"
                                                   aria-label="Next">
                                                    <span aria-hidden="true">&raquo;</span>
                                                </a>
                                            </li>
                                        </c:if>

                                        <li><a
                                            href="${pageContext.request.contextPath}/tbOrder/searchOrders?page=${tbOrderPageInfos.pages }">末页</a>
                                        </li>
                                    </ul>

                                </td>
                            </tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="${pageContext.request.contextPath}/resources/jquery/jquery-2.1.1.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/script/docs.min.js"></script>
<script type="text/javascript">
    $(function () {

        $("[data-toggle='tooltip']").tooltip();

        $(".list-group-item").click(function () {
            if ($(this).find("ul")) {
                $(this).toggleClass("tree-closed");
                if ($(this).hasClass("tree-closed")) {
                    $("ul", this).hide("fast");
                } else {
                    $("ul", this).show("fast");
                }
            }
        });

    });
    //查看订单详情
    function lookDetail(tbOrderId, type) {
        // alert(tbOrderId+"=========="+type);
        location.replace("/tbOrder/selectTbOrder?tbOrderId=" + tbOrderId + "&type=" + type)

    }
    //设置报修单的状态
    function setStatu(tbOrderId, type) {
        //alert(tbOrderId+"=========="+type);
        if (confirm("确认操作？")) {
            location.replace("/tbOrder/selectTbOrder?tbOrderId=" + tbOrderId + "&type=" + type)
        }
    }
    //设置订单是否有效
    function DongJieOrder(tbOrderId, isDeleted) {
        //alert(tbOrderId+"=========="+isDeleted);
        if (confirm("请确认操作")) {
            $.ajax({
                url: '/tbOrder/DongJieTbOrder',

                data: {
                    orderId: tbOrderId,
                    isDeleted: isDeleted
                },
                type: 'GET',
                dataType: 'json',
                success: function (data) {
                    if (data.flag) {
                        alert(data.msg);
                        location.reload()
                    } else {
                        alert(data.msg);
                    }
                }
            });
        } else {
            location.reload()
        }
    }
    //删除报修单
    function DeleteOrder(tbOrderId) {
        //alert(tbOrderId+"==========");
        if (confirm("请确认操作")) {
            $.ajax({
                url: '/tbOrder/DeleteOrder',

                data: {
                    orderId: tbOrderId,
                },
                type: 'GET',
                dataType: 'json',
                success: function (data) {
                    if (data.flag) {
                        alert(data.msg);
                        // location.reload()
                        location.replace("/tbOrder/searchOrders")
                    } else {
                        alert(data.msg);
                    }
                }
            });
        } else {
            // location.reload()
            location.replace("/tbOrder/searchOrders")
        }
    }
    //指派维修负责人
    function zdleader(tbOrderId) {
        //alert(tbOrderId+"=========="+isDeleted);
        if (confirm("确认操作？")) {
            location.replace("/tbOrder/selectLeader?orderId=" + tbOrderId)
        }
    }
</script>
</body>
</html>
